//
//  HYWalletBtn.m
//  HaiYue
//
//  Created by skyline on 2018/1/5.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYWalletBtn.h"
@interface HYWalletBtn ()
@property (nonatomic, strong) HYImageView *IMG;
@property (nonatomic, strong) HYImageView *rightIMG;
@property (nonatomic, strong) HYLabel *titleLBL;
@property (nonatomic, strong) HYLabel *contentLBL;
@end
@implementation HYWalletBtn
- (instancetype)initWithTitle:(NSString *)title imageName:(NSString *)iamgeName
{
    self = [super init];
    if (self)
    {
        self.IMG.image = [UIImage imageNamed:iamgeName];
        self.titleLBL.text = title;
        self.contentLBL.hidden = NO;
        self.rightIMG.hidden = NO;
    }
    return self;
}

- (HYImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[HYImageView alloc]initWithImage:nil cornerRadius:20 - GAP];
        [self addSubview:_IMG];
        [_IMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP / 2.0);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(self.IMG.bounds.size);
        }];
    }
    return _IMG;
}

- (HYLabel *)titleLBL
{
    if (!_titleLBL)
    {
       _titleLBL = [[HYLabel alloc]initWithText:@"" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:15]];
        [self addSubview:_titleLBL];
        [_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.IMG.mas_right).with.offset(GAP / 2.0);
            make.centerY.equalTo(self);
        }];
    }
    return _titleLBL;
}

- (HYLabel *)contentLBL
{
    if (!_contentLBL)
    {
        _contentLBL = [[HYLabel alloc]initWithText:@"0" textColor:RED_COLOR textFont:[UIFont systemFontOfSize:15]];
        [self addSubview:_contentLBL];
        [_contentLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.rightIMG.mas_left).with.offset(-GAP / 2.0);
            make.centerY.equalTo(self);
        }];
    }
    return _contentLBL;
}

- (HYImageView *)rightIMG
{
    if (!_rightIMG)
    {
       _rightIMG = [[HYImageView alloc]initWithImage:[UIImage imageNamed:@"rightArrow_select"]];
        _rightIMG.bounds = CGRectMake(0, 0, HYCellRightArrowWidth, HYCellRightArrowHeight);
        [self addSubview:_rightIMG];
        [_rightIMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).with.offset(- GAP / 2.0);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(self.rightIMG.bounds.size);
        }];
    }
    return _rightIMG;
}
- (void)setContent:(NSString *)content
{
    if (_content != content)
    {
        _content = content;
        self.contentLBL.text = _content;
    }
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self sendActionsForControlEvents:UIControlEventTouchUpInside];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
